package com.ht.controller;

import com.ht.data.Result;
import com.ht.domain.bo.TbHospitalBO;
import com.ht.domain.bo.TbLevelBO;
import com.ht.domain.bo.TbScheduleBO;
import com.ht.domain.vo.TbHospitalVO;
import com.ht.domain.vo.TbLevelVO;
import com.ht.domain.vo.TbScheduleVO;
import com.ht.feign.AppointmentRegisteredFeign;
import com.ht.feign.PublicOutpatientFeign;
import com.ht.service.TbCittesService;
import com.ht.service.TbLevelService;
import com.ht.service.TbScheduleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController  //等于@Restquest + @Controller
@RequestMapping("/appointment")
@Api("专家门诊挂号管理系统")
@RefreshScope  //实时刷新
public class AppointmentController {
    @Autowired
    private TbCittesService tbCittesService;

    @Autowired
    private AppointmentRegisteredFeign appointmentRegisteredFeign;

    @Autowired
    private PublicOutpatientFeign publicOutpatientFeign;

    @Autowired
    private TbLevelService tbLevelService;

    @Autowired
    private TbScheduleService tbScheduleService;


    /**
     *根据省id查询该省该区所对应的医院  -----判断有无具体cityId传过来
     * @param provinceId 省id
     * @param cityId      市id
     * @return
     */
    @GetMapping("/queryHospitalByprocincesId/{provinceId}")
    @ApiOperation("根据省id查询该省该区所对应的医院")
    @ApiImplicitParam()
    public Result queryHospitalByprocincesId(@PathVariable("provinceId") Long provinceId, Long cityId){
        List<TbHospitalVO> listt  = new ArrayList<>();
        if (cityId != null){
            List<TbHospitalBO> list = tbCittesService.queryProvincesByCityId(cityId);
            list.forEach(obj->{
                TbHospitalVO vo = new TbHospitalVO();
                BeanUtils.copyProperties(obj,vo);
                listt.add(vo);
            });
        }else{
            List<TbHospitalBO> list = tbCittesService.queryProvincesByprocincesId(provinceId);
            list.forEach(obj->{
                TbHospitalVO vo = new TbHospitalVO();
                BeanUtils.copyProperties(obj,vo);
                listt.add(vo);
            });
        }
        return Result.OK().setData(listt);
    }

    @GetMapping("/querypartment")
    @ApiOperation("查询所有科室")
    @ApiImplicitParam()
    public Result querypartment(){
        Result all = publicOutpatientFeign.findDepartmentAll();
        return all;
    }

    @GetMapping("/queryDoctorLevel")
    @ApiOperation("查询所有医生职称")
    @ApiImplicitParam()
    public Result queryDoctorLevel(){
        List<TbLevelBO> list = tbLevelService.queryDoctorLevel();
        List<TbLevelVO> listt = new ArrayList<>();
        list.forEach(obj->{
            TbLevelVO vo = new TbLevelVO();
            BeanUtils.copyProperties(obj,vo);
            listt.add(vo);
        });
        return Result.OK().setData(listt);
    }

    /**
     *
     * @param departmentId   科室id
     * @param levelId        职称
     * @param score          热度   0/不查  1/查
     * @return
     */

    @GetMapping("/queryDoctorBydepartmentId/{departmentId}/{levelId}/{score}")
    @ApiOperation("根据科室id查询该省该区所对应的医生")
    @ApiImplicitParam()
    public Result queryDoctorBydepartmentId(@PathVariable("departmentId") Long departmentId,@PathVariable("levelId")Long levelId,@PathVariable("score")Long score){
        Result result = appointmentRegisteredFeign.queryDoctorBydepartmentIdAndStatus(departmentId, 0,levelId,score);
        return result;
    }

    /**
     *根据时间查询所对应的医生
     * @param format  时间
     * @return
     */
    @GetMapping("/queryDoctorBydata")
    @ApiOperation("根据时间查询所对应的医生")
    @ApiImplicitParam()
    public Result queryDoctorBydata(String format){
        List<TbScheduleBO> list = tbScheduleService.queryDoctorBydata(format);
        List<TbScheduleVO> listt = new ArrayList<>();
        list.forEach(obj->{
            TbScheduleVO vo = new TbScheduleVO();
            BeanUtils.copyProperties(obj,vo);
            listt.add(vo);
        });
        return Result.OK().setData(listt);
    }

    //TODO----以上详情页



}
